<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/>
<title></title>

<link href="<%=contextPath %>/static/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="<%=contextPath %>/static/css/font-awesome.min.css" />

<link rel="stylesheet" href="<%=contextPath %>/static/css/ace.min.css" />
<link rel="stylesheet" href="<%=contextPath %>/static/css/ace-responsive.min.css" />
<link rel="stylesheet" href="<%=contextPath %>/static/css/ace-skins.min.css" />
<link rel="stylesheet" href="<%=contextPath %>/plugins/zTree_v3/css/zTreeStyle/zTreeStyle.css" />

<script type="text/javascript" src="<%=contextPath %>/static/js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="<%=contextPath %>/plugins/zTree_v3/js/jquery.ztree.core.min.js"></script>
<script type="text/javascript" src="<%=contextPath %>/plugins/zTree_v3/js/jquery.ztree.excheck.min.js"></script>
<!-- ajax表单提交-->
<script src="<%=contextPath %>/js/jquery.form.js"></script>

<style type="text/css">
footer{height:50px;position:fixed;bottom:0px;left:0px;width:100%;text-align: center;}
</style>

</head>
<body>
	<div id="zhongxin"  style="padding-bottom: 50px;" >
		<ul id="tree" class="ztree"></ul>
		<input type="hidden" id="tempids" value="" />
		<input type="hidden" id="tempnames" value="" />
	</div>
	<div id="zhongxin2" class="center" style="display:none"><br/><br/><br/><br/><img src="<%=contextPath %>/static/images/jiazai.gif" /><br/><h4 class="lighter block green"></h4></div>
	
	
	<script type="text/javascript">
	<c:if test="${tops eq 0}">
	  $(top.hangge());	
	</c:if>
	var zTree;
	var treeNodes;
	$(document).ready(function(){
		var setting = {
				check: {
					enable: true,
					chkboxType: {"Y":"", "N":""}
				},
				view: {
					dblClickExpand: false
				},
				data: {
					simpleData: {
						enable: true
					}
				}
			};

			var zNodes =[];

			function nocheckNode(e) {
				var zTree = $.fn.zTree.getZTreeObj("tree"),
				nocheck = e.data.nocheck,
				nodes = zTree.getSelectedNodes();
				if (nodes.length == 0) {
					alert("请先选择一个节点");
				}
				if(nodes.length>3){
	                treeNode.checked=false;
	                alert("勾选的数量不能超过3个！");
	            }

				for (var i=0, l=nodes.length; i<l; i++) {
					nodes[i].nocheck = nocheck;
					zTree.updateNode(nodes[i]);
				}
			}

			$(document).ready(function(){
				zTree = $.fn.zTree.init($("#tree"), setting, zNodes);
			});
			
			var ids = '${ids}';
			  $.ajax({  
			        async : false,  
			        cache:false, 
			        type: 'POST',  
			        dataType : "json",  
			        url:"<%=contextPath %>/language/getZtreeJson",
			        data:{ids:ids},
			        error: function () {//请求失败处理函数  
			            alert('请求失败');  
			        },  
			        success:function(data){ //请求成功后处理函数。    
			        	zNodes = data;   //把后台封装好的简单Json格式赋给treeNodes  
			        }  
			    });  
		});
		 function save(){
				var nodes = zTree.getCheckedNodes();
				var tmpNode;
				var ids = "";
				var names ="";
				for(var i=0; i<nodes.length; i++){
					if(nodes.length >3){
						alert("语言选择数量不能大于3！");
						return;
					}
					tmpNode = nodes[i];
					if(i!=nodes.length-1){
						ids += tmpNode.id+",";
						names +=tmpNode.name+",";
					}else{
						ids += tmpNode.id;
						names += tmpNode.name
					}
				}
				$("#tempids").val(ids);
				$("#tempnames").val(names);
				top.Dialog.close();
		 }
	</script>
	<footer>
	<div style="width: 100%;" class="center" >
		<a class="btn btn-mini btn-primary" onclick="save();">确认</a>
		<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
	</div>
	</footer>
</body>
</html>